import { ref } from 'vue'
import { getCheckFlowTemplateById } from '@/api/basic'

/**
 * 审批流模板详情服务
 */
export default function () {
  const getCheckFlowTemplateDetailLoading = ref(false)
  const checkFlowTemplateDetail = ref<BaseInfoAPIResponse.CheckFlowTemplateDetail>({
    code: '',
    description: '',
    gmtCreate: '',
    gmtUpdate: '',
    id: 0,
    name: '',
  })

  const getCheckFlowTemplateDetail = async (templateId: string) => {
    try {
      getCheckFlowTemplateDetailLoading.value = true
      const res = await getCheckFlowTemplateById(templateId)
      getCheckFlowTemplateDetailLoading.value = false
      if (res.data.code === 20000) {
        checkFlowTemplateDetail.value = res.data.data.data
        return ''
      }

      return res.data.message
    } catch (e) {
      getCheckFlowTemplateDetailLoading.value = true
      return '获取模板信息失败，请稍后重试'
    }
  }

  return {
    checkFlowTemplateDetail,
    getCheckFlowTemplateDetailLoading,
    getCheckFlowTemplateDetail,
  }
}
